<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ZooKeeper 大规模集群性能优化指南</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
            border: 1px solid transparent;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
            border-color: #667eea;
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 24px;
            background: linear-gradient(to bottom, #667eea, #764ba2);
            border-radius: 2px;
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            padding: 16px;
            border-radius: 8px;
            font-family: 'Consolas', 'Monaco', monospace;
            overflow-x: auto;
        }
        
        .metric-card {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 24px;
            border-radius: 12px;
            text-align: center;
            transition: transform 0.3s ease;
        }
        
        .metric-card:hover {
            transform: scale(1.05);
        }
        
        .first-letter {
            float: left;
            font-size: 4em;
            line-height: 0.8;
            margin: 0.1em 0.1em 0 0;
            font-weight: 700;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white">
        <div class="container mx-auto px-6 py-20">
            <div class="max-w-4xl mx-auto text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6 leading-tight">
                    ZooKeeper 大规模集群<br>性能优化指南
                </h1>
                <p class="text-xl md:text-2xl opacity-90 mb-8">
                    掌握分布式协调服务的核心调优策略
                </p>
                <div class="flex justify-center space-x-6 text-lg">
                    <div class="flex items-center">
                        <i class="fas fa-server mr-2"></i>
                        <span>企业级架构</span>
                    </div>
                    <div class="flex items-center">
                        <i class="fas fa-tachometer-alt mr-2"></i>
                        <span>性能优化</span>
                    </div>
                    <div class="flex items-center">
                        <i class="fas fa-shield-alt mr-2"></i>
                        <span>高可用保障</span>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-12">
        <!-- Introduction -->
        <div class="max-w-4xl mx-auto mb-16">
            <div class="bg-white rounded-2xl shadow-xl p-8">
                <p class="text-lg leading-relaxed text-gray-700">
                    <span class="first-letter">在</span>大规模集群中，ZooKeeper 的性能优化至关重要，因为它作为一个分布式协调服务，在许多微服务和大数据架构中扮演着核心角色。为了确保其高效性和稳定性，以下是一些关键的调优策略和参数设置。
                </p>
            </div>
        </div>

        <!-- Performance Metrics -->
        <div class="max-w-6xl mx-auto mb-16">
            <div class="grid grid-cols-1 md:grid-cols-3 gap-6">
                <div class="metric-card">
                    <i class="fas fa-rocket text-4xl mb-4"></i>
                    <h3 class="text-2xl font-bold mb-2">99.9%</h3>
                    <p class="text-lg">服务可用性</p>
                </div>
                <div class="metric-card">
                    <i class="fas fa-bolt text-4xl mb-4"></i>
                    <h3 class="text-2xl font-bold mb-2">&lt;10ms</h3>
                    <p class="text-lg">平均响应时间</p>
                </div>
                <div class="metric-card">
                    <i class="fas fa-network-wired text-4xl mb-4"></i>
                    <h3 class="text-2xl font-bold mb-2">10K+</h3>
                    <p class="text-lg">并发连接数</p>
                </div>
            </div>
        </div>

        <!-- Architecture Diagram -->
        <div class="max-w-6xl mx-auto mb-16">
            <div class="bg-white rounded-2xl shadow-xl p-8">
                <h2 class="text-3xl font-bold mb-8 text-center text-gray-800">ZooKeeper 集群架构</h2>
                <div class="mermaid">
                    graph TB
                        subgraph "ZooKeeper Ensemble"
                            L[Leader Node]
                            F1[Follower 1]
                            F2[Follower 2]
                            F3[Follower 3]
                            O[Observer]
                        end
                        
                        subgraph "Client Applications"
                            C1[Service A]
                            C2[Service B]
                            C3[Service C]
                        end
                        
                        C1 -.->|Read/Write| L
                        C2 -.->|Read| F1
                        C3 -.->|Read| F2
                        
                        L -->|Sync| F1
                        L -->|Sync| F2
                        L -->|Sync| F3
                        L -->|Broadcast| O
                        
                        style L fill:#667eea,stroke:#fff,stroke-width:3px,color:#fff
                        style F1 fill:#764ba2,stroke:#fff,stroke-width:2px,color:#fff
                        style F2 fill:#764ba2,stroke:#fff,stroke-width:2px,color:#fff
                        style F3 fill:#764ba2,stroke:#fff,stroke-width:2px,color:#fff
                        style O fill:#a855f7,stroke:#fff,stroke-width:2px,color:#fff
                </div>
            </div>
        </div>

        <!-- Optimization Strategies -->
        <div class="max-w-6xl mx-auto">
            <div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
                
                <!-- 1. 集群规模 -->
                <div class="bg-white rounded-xl shadow-lg p-8 card-hover">
                    <h3 class="text-2xl font-bold mb-4 section-title text-gray-800">
                        <i class="fas fa-server text-purple-600 mr-3"></i>选择合适的集群规模
                    </h3>
                    <div class="space-y-4 text-gray-700">
                        <div>
                            <h4 class="font-semibold text-lg mb-2">节点数配置</h4>
                            <p class="leading-relaxed">ZooKeeper 集群通常由奇数个节点组成，以便实现有效的选举和故障恢复。建议至少使用 3 个节点，最佳实践为 5 个或 7 个节点。增加节点数可以提高系统的容错性和可用性，但也会增加网络开销。</p>
                        </div>
                        <div class="bg-purple-50 p-4 rounded-lg">
                            <p class="text-sm"><i class="fas fa-lightbulb text-purple-600 mr-2"></i><strong>最佳实践：</strong>生产环境推荐使用 5 节点集群，可容忍 2 个节点故障。</p>
                        </div>
                    </div>
                </div>

                <!-- 2. JVM 参数 -->
                <div class="bg-white rounded-xl shadow-lg p-8 card-hover">
                    <h3 class="text-2xl font-bold mb-4 section-title text-gray-800">
                        <i class="fas fa-memory text-purple-600 mr-3"></i>配置 JVM 参数
                    </h3>
                    <div class="space-y-4">
                        <div>
                            <h4 class="font-semibold text-lg mb-2">堆大小设置</h4>
                            <p class="text-gray-700 mb-3">增加 ZooKeeper 的 JVM 堆大小可以提升性能。</p>
                            <div class="code-block">
                                -Xmx2g -Xms2g
                            </div>
                        </div>
                        <div>
                            <h4 class="font-semibold text-lg mb-2 mt-4">垃圾收集策略</h4>
                            <p class="text-gray-700 mb-3">使用 G1 GC 减少停顿时间：</p>
                            <div class="code-block">
                                -XX:+UseG1GC
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 3. ZooKeeper 配置 -->
                <div class="bg-white rounded-xl shadow-lg p-8 card-hover">
                    <h3 class="text-2xl font-bold mb-4 section-title text-gray-800">
                        <i class="fas fa-cogs text-purple-600 mr-3"></i>调整 ZooKeeper 配置
                    </h3>
                    <div class="space-y-4 text-gray-700">
                        <div class="grid grid-cols-1 gap-4">
                            <div class="bg-gray-50 p-4 rounded-lg">
                                <h4 class="font-semibold mb-2">tickTime</h4>
                                <p class="text-sm">基本时间单位，默认 2000ms，可根据网络延迟调整</p>
                            </div>
                            <div class="bg-gray-50 p-4 rounded-lg">
                                <h4 class="font-semibold mb-2">initLimit & syncLimit</h4>
                                <p class="text-sm">控制节点初始化和同步超时，高延迟环境需增大</p>
                            </div>
                            <div class="bg-gray-50 p-4 rounded-lg">
                                <h4 class="font-semibold mb-2">maxClientCnxns</h4>
                                <p class="text-sm">限制每个客户端最大连接数，保护服务器资源</p>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 4. 数据模型 -->
                <div class="bg-white rounded-xl shadow-lg p-8 card-hover">
                    <h3 class="text-2xl font-bold mb-4 section-title text-gray-800">
                        <i class="fas fa-database text-purple-600 mr-3"></i>优化数据模型
                    </h3>
                    <div class="space-y-4 text-gray-700">
                        <div>
                            <h4 class="font-semibold text-lg mb-2">数据结构设计</h4>
                            <ul class="space-y-2">
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-green-500 mr-2 mt-1"></i>
                                    <span>保持节点扁平结构，避免过深的树形层级</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-green-500 mr-2 mt-1"></i>
                                    <span>使用轻量级序列化格式（JSON、Protocol Buffers）</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-green-500 mr-2 mt-1"></i>
                                    <span>合理设计节点命名规范，便于管理和查询</span>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>

                <!-- 5. 客户端优化 -->
                <div class="bg-white rounded-xl shadow-lg p-8 card-hover">
                    <h3 class="text-2xl font-bold mb-4 section-title text-gray-800">
                        <i class="fas fa-laptop-code text-purple-600 mr-3"></i>客户端优化
                    </h3>
                    <div class="space-y-4 text-gray-700">
                        <div>
                            <h4 class="font-semibold text-lg mb-2